package br.perfiman.helpers;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import br.perfiman.model.Account;
import br.perfiman.model.Asset;
import br.perfiman.model.Broker;
import br.perfiman.model.Category;
import br.perfiman.model.CreditCard;
import br.perfiman.model.Person;
import br.perfiman.service.AccountService;
import br.perfiman.service.AssetService;
import br.perfiman.service.BrokerService;
import br.perfiman.service.CategoryService;
import br.perfiman.service.CreditCardService;
import br.perfiman.service.PersonService;
import br.perfiman.utils.ServiceLocator;

public class GeneralComboHelper {

	public static List<SelectItem> getAssets() throws Exception{
		AssetService assetService = (AssetService) ServiceLocator.getInstance().get("AssetServiceBean/remote");
		List<Asset> assetList = assetService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(Asset obj: assetList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}

	public static List<SelectItem> getAccounts() throws Exception{
		AccountService accountService = (AccountService) ServiceLocator.getInstance().get("AccountServiceBean/remote");
		List<Account> accountList = accountService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(Account obj: accountList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}

	public static List<SelectItem> getCreditCards() throws Exception{
		CreditCardService creditCardService = (CreditCardService) ServiceLocator.getInstance().get("CreditCardServiceBean/remote");
		List<CreditCard> creditCardList = creditCardService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(CreditCard obj: creditCardList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}

	public static List<SelectItem> getCategorys() throws Exception{
		CategoryService categoryService = (CategoryService) ServiceLocator.getInstance().get("CategoryServiceBean/remote");
		List<Category> categoryList = categoryService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(Category obj: categoryList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}

	public static List<SelectItem> getPersons() throws Exception{
		PersonService personService = (PersonService) ServiceLocator.getInstance().get("PersonServiceBean/remote");
		List<Person> personList = personService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(Person obj: personList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}
	
	public static List<SelectItem> getBrokers() throws Exception{
		BrokerService brokerService = (BrokerService) ServiceLocator.getInstance().get("BrokerServiceBean/remote");
		List<Broker> brokerList = brokerService.retrieveAll();
		List<SelectItem> itens = new ArrayList<SelectItem>();
		for(Broker obj: brokerList){
			SelectItem item = new SelectItem();
			item.setLabel(obj.getName());
			item.setValue(obj.getId());
			itens.add(item);
		}
		return itens;
	}
}
